function ts_main1(digits: number[]): number[] {
  let index = digits.length - 1;
  while (true) {
    if (digits[index] < 9) {
      digits[index] += 1;
      return digits;
    }
    digits[index] = 0;
    if (index > 0) {
      index -= 1;
    } else {
      break;
    }
  }
  digits = [1, ...digits];
  return digits;
}

console.log(ts_main1([1, 2, 3]));
console.log(ts_main1([4, 3, 2, 1]));
console.log(ts_main1([0]));
console.log(ts_main1([9, 9]));
